# 导包
from urllib import request,parse
import json


def fanyi(msg):
    for pnage in range(pn,pn2+1):
        num = (pnage-1)*50

        newurl = base_url + kw + '&'+'pn='+str(num)
        response = request.urlopen(newurl)
        # 处理响应信息
        html = response.read().decode('utf-8')

        with open('./'+('%s' % pnage)+'.html', 'w', encoding='utf-8') as f:
            f.write(html)

while True:
    msg = input('请输入要翻译的内容：')
    pn = int(input('请输入要页数：'))
    pn2 = int(input('请输入要结束：'))
    # url地址
    base_url = 'http://tieba.baidu.com/f?'
    # 数据格式化
    data = {'kw': msg}
    kw = parse.urlencode(data)
    fanyi(msg)